library(tidyverse)
table1

table4a
table4a %>% 
  gather('1999', '2000', key = 'year', value = 'cases')

table4b %>% 
  gather('1999', '2000', key = "year", value = "pop")

table2
spread(table2, key = type, value = count)

table3
table3 %>% 
  separate(rate, into = c("cases", "population"))

stocks <- tibble(
  year   = c(2015, 2015, 2015, 2015, 2016, 2016, 2016),
  qtr    = c(   1,    2,    3,    4,    2,    3,    4),
  return = c(1.88, 0.59, 0.35,   NA, 0.92, 0.17, 2.66)
)

stocks %>% 
  spread(year, return) %>% 
  gather(year, return, '2015':'2016', na.rm = TRUE)

stocks %>% complete(year, qtr)

who
